<?php


class Helper extends Base_Controller
{
	
	
	public function __construct()
	{
		parent::__construct();
		$this->load->model('helper_mdl','helper');
	}
	
	/**
	 * 
	 * 关于我们
	 */
	public function about()
	{
		$about = $this->helper->getByTag( 'about' );

		$data['about'] = $about;
		$this->load->library( 'fckeditor','form1' );
		$this->fckeditor->InstanceName = 'content';
	    $this->fckeditor->ToolbarSet = 'Default';
	    $this->fckeditor->Height = 800;
	    $this->fckeditor->Value = $about['content'];
	    
	    $data['fckeditor']=$this->fckeditor->CreateHtml();
	    
		$this->load->view( 'adminroot/about', $data );
		
	}
	
	/**
	 * 修改
	 */
	
	public function about_update()
	{
		$config['tag'] = 'about';
		$data['content'] = $this->input->post( 'content' );
		$this->helper->updateByTag( $config, $data);
		
	}
	
	/**
	 * 
	 */
	
	public function join()
	{
		$about = $this->helper->getByTag( 'join' );

		$data['about'] = $about;
		$this->load->library( 'fckeditor','form1' );
		$this->fckeditor->InstanceName = 'content';
		$this->fckeditor->Height = 800;
	    $this->fckeditor->ToolbarSet = 'Default';
	   $this->fckeditor->Value = $about['content'];
	    
	    $data['fckeditor']=$this->fckeditor->CreateHtml();
	    
		$this->load->view( 'adminroot/join', $data );
	}
	
	/**
	 * 修改
	 */
	
	public function join_update()
	{
		$config['tag'] = 'join';
		$data['content'] = $this->input->post( 'content' );
		$this->helper->updateByTag( $config, $data);
		
	}
	
	/**
	 * 
	 */
	
	public function juan()
	{
		$about = $this->helper->getByTag( 'juan' );

		$data['about'] = $about;
		$this->load->library( 'fckeditor','form1' );
		$this->fckeditor->InstanceName = 'content';
	    $this->fckeditor->ToolbarSet = 'Default';
	    $this->fckeditor->Height = 800;
	   $this->fckeditor->Value = $about['content'];
	    
	    $data['fckeditor']=$this->fckeditor->CreateHtml();
	    
		$this->load->view( 'adminroot/juan', $data );
	}
	
	/**
	 * 修改
	 */
	
	public function juan_update()
	{
		$config['tag'] = 'juan';
		$data['content'] = $this->input->post( 'content' );
		$this->helper->updateByTag( $config, $data);
		
	}
	
	/**
	 * 
	 */
	
	public function fawu()
	{
		$about = $this->helper->getByTag( 'fawu' );

		$data['about'] = $about;
		$this->load->library( 'fckeditor','form1' );
		$this->fckeditor->InstanceName = 'content';
	    $this->fckeditor->ToolbarSet = 'Default';
	    $this->fckeditor->Height = 800;
	   $this->fckeditor->Value = $about['content'];
	    
	    $data['fckeditor']=$this->fckeditor->CreateHtml();
	    
		$this->load->view( 'adminroot/fawu', $data );
	}
	
	/**
	 * 修改
	 */
	
	public function fawu_update()
	{
		$config['tag'] = 'fawu';
		$data['content'] = $this->input->post( 'content' );
		$this->helper->updateByTag( $config, $data);
		
	}
	
	/**
	 * 合作
	 */
	
	public function hezuo()
	{
		$about = $this->helper->getByTag( 'hezuo' );

		$data['about'] = $about;
		$this->load->library( 'fckeditor','form1' );
		$this->fckeditor->InstanceName = 'content';
	    $this->fckeditor->ToolbarSet = 'Default';
	    $this->fckeditor->Height = 800;
	    $this->fckeditor->Value = $about['content'];
	    
	    $data['fckeditor']=$this->fckeditor->CreateHtml();
	    
		$this->load->view( 'adminroot/hezuo', $data );
	}
	
	/**
	 * 合作修改
	 */
	
	public function hezuo_update()
	{
		$config['tag'] = 'hezuo';
		$data['content'] = $this->input->post( 'content' );
		$this->helper->updateByTag( $config, $data);
		
	}
	
	/**
	 * 合作
	 */
	
	public function bangzhu()
	{
		$about = $this->helper->getByTag( 'bangzhu' );

		$data['about'] = $about;
		$this->load->library( 'fckeditor','form1' );
		$this->fckeditor->InstanceName = 'content';
	    $this->fckeditor->ToolbarSet = 'Default';
	    $this->fckeditor->Height = 800;
	   $this->fckeditor->Value = $about['content'];
	    
	    $data['fckeditor']=$this->fckeditor->CreateHtml();
	    
		$this->load->view( 'adminroot/bangzhu', $data );
	}
	
	/**
	 * 合作修改
	 */
	
	public function bangzhu_update()
	{
		$config['tag'] = 'bangzhu';
		$data['content'] = $this->input->post( 'content' );
		$this->helper->updateByTag( $config, $data);
		
	}
	
	/**
	 * 
	 * 通告列表
	 */
	public function tonggao()
	{
		$this->load->model( 'tonggao_mdl', 'tonggao' );
		/*分页设置*/
		$enabled = intval($this->uri->rsegment(4));
		$page = $this->uri->rsegment(6);
	
		$page = ($page && is_numeric($page)) ? intval($page) : 1;
		$limit = 10;
		$offset = ($page - 1) * $limit;
		$pagination = '';
		
		$count = $this->tonggao->getTonggaoCount();
	
		$this->load->library('pagination');
		$config['base_url'] = base_url().'/news/index/page/';
		$config['total_rows'] = $count;
		//设置url上第几段用于传递分页器的偏移量
		$config ['uri_segment'] = 7;	 
		$config['per_page'] = $limit; 
		$config['use_page_numbers'] = TRUE;
		$this->pagination->initialize($config); 
		
		$list = array();
		
		$list = $this->tonggao->getTonggaoList( true,$limit, $offset,'DESC', 'tonggao' );
		$data['list'] = $list;
		$this->load->view( 'adminroot/tonggao', $data );
	}
	
	/**
	 * 
	 * 添加通告
	 */
	
	public function tonggao_add()
	{
		$this->load->library('form_validation');
		$this->load->model( 'tonggao_mdl', 'tonggao' );
		$this->_load_validation_rules();
		
		if ( $this->form_validation->run() == FALSE ) {
			
			$this->load->library( 'fckeditor','content' );
			$this->fckeditor->InstanceName = 'content';
	        $this->fckeditor->ToolbarSet = 'Default';
	        $this->fckeditor->Height = 800;
	        $data['fckeditor']=$this->fckeditor->CreateHtml();
	        
			$this->load->view( 'adminroot/tonggao_add', $data );
			
		} else {
			$this->load->model( 'tonggao_mdl', 'tonggao' );
			$data['title']      = $this->input->post( 'title' );
			$data['tag']   = 'tonggao';
			$data['content']       = $this->input->post( 'content' );
			$data['rank']      = $this->input->post( 'rank' );
			$data['createtime']    = time();
			
			if ( $this->tonggao->tonggaoAdd( $data )) {
				
				redirect( 'adminroot/helper/tonggao' );
				
			}		
		}
	}
	
	
	/**
	 * 修改通告
	 */
	
	public function edit()
	{
		$this->load->model( 'tonggao_mdl', 'tonggao' );
		$id = intval( $this->uri->rsegment(4) );
		$tonggao = $this->tonggao->getTonggaoById($id);
		$data['tonggao'] = $tonggao;
		
		$this->load->library( 'fckeditor','content' );
		$this->fckeditor->InstanceName = 'content';
	    $this->fckeditor->ToolbarSet = 'Default';
	    $this->fckeditor->Height = 800;
	     $this->fckeditor->Value = $tonggao['content'];
	    $data['fckeditor']=$this->fckeditor->CreateHtml();
		
	    $this->load->view('adminroot/tonggao_edit', $data);
	}
	
	/**
	 * 更新通告
	 */
	
	public function update()
	{
		
		$this->load->library('form_validation');
		$this->_load_validation_rules();
		
		if ( $this->form_validation->run() == true ) {
			
			$id = $this->input->post("id");
			$this->load->model( 'tonggao_mdl', 'tonggao' );
			$data['title']      = $this->input->post( 'title' );
			$data['tag']   = 'tonggao';
			$data['content']       = $this->input->post( 'content' );
			$data['rank']      = $this->input->post( 'rank' );
			$data['createtime']    = time();
			
			$config['id'] = $id;
			
			if ( $this->tonggao->tonggaoUpdate( $data, $config )) {
				
				redirect( 'adminroot/helper/tonggao' );
				
			}
		} 
	}
	
	public function del( $id )
	{
		$this->load->model( 'tonggao_mdl', 'tonggao' );
		
		$id = intval( $this->uri->rsegment(4) );
		$this->tonggao->deltonggao( $id );
		redirect( 'adminroot/helper/tonggao' );
	}
	
	/**
	 * 
	 * 表单验证
	 */
	private function _load_validation_rules()
	{
		$this->form_validation->set_error_delimiters('<li>', '</li>');
		$this->form_validation->set_rules('title','标题','required|xss_clean');

	}
	
	/**
	 * 修改内容
	 */
	
	
}